package com.itheima.service.backend.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.common.entity.PageResult;
import com.itheima.mapper.backend.SetMealMapper;
import com.itheima.pojo.Setmeal;
import com.itheima.service.backend.SetMealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SetMealServiceImpl implements SetMealService {
    @Autowired
    SetMealMapper setMealMapper;

    @Override
    public PageResult page(Integer page, Integer pageSize, String name) {
        //1. 设置分页参数
        PageHelper.startPage(page,pageSize);

        //2. 执行查询
        List<Setmeal> setmealList = setMealMapper.list(name);
        Page<Setmeal> pageBean = (Page<Setmeal>) setmealList;


        //3. 封装PageBean对象
        PageResult pageResult = new PageResult(pageBean.getTotal(),pageBean.getResult());
        return pageResult;
    }

    @Override
    public Setmeal findById(Integer id) {
        return setMealMapper.findById(id);
    }
}
